package com.aopproxy;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext("com.aopproxy");
        IntfA bean = context.getBean(IntfA.class);
        System.out.println(bean.getClass());
        printBeanDefinition(context);
        //bean.doSth();


        IntfAImpl bean2 = context.getBean(IntfAImpl.class);
        System.out.println(bean2.getClass());
        System.out.println(bean == bean2);

    }

    private static void printBeanDefinition(ApplicationContext context) {
        ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) context;
        ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) configurableApplicationContext.getBeanFactory();
        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println("name---:" + name);
            BeanDefinition definition = factory.getBeanDefinition(name);
            System.out.println("definition class: ---" + definition.getBeanClassName());
        }
    }
}
